package com.dormitoryAdministratorSystem.dao.user.impl;

import com.dormitoryAdministratorSystem.dao.user.IUserDao;
import com.dormitoryAdministratorSystem.entity.user.UserBean;
import com.dormitoryAdministratorSystem.util.DBUtil;

import java.sql.ResultSet;

public class UserDaoImpl implements IUserDao {
    @Override
    public UserBean getUser(String username, String pwd) {
        UserBean user = null;

        String sql = "select * from t_user where uname = ? and pwd = md5( ? )";
        ResultSet rSet = DBUtil.excuteQuery(sql,username,pwd);

        try{
            while(rSet.next()){
                user = new UserBean();
                user.setUId(rSet.getInt("uId"));
                user.setUsername(rSet.getString("uname"));
                user.setPassword(rSet.getString("pwd"));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }

        return user;
    }
}
